/**
 * 
 */
package com.tcc.assessment.facultyrole;

import org.apache.xpath.operations.String;
import org.openqa.jetty.html.List;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.tcc.assessment.AssessmentIdMapping;
import com.tcc.assessment.studentrole.allowchangeanswer.Assessment1;
import com.tcc.nav.logic.NavFinder;
import com.tcc.qa.test.util.BaseTest;
import com.tcc.qa.test.util.ButtonFinder;
import com.tcc.qa.test.util.LinkFinder;
import com.tcc.qa.test.util.SelLogger;

/**
 * @company CampusCruiser
 * @author Emily_Wang
 * @date 2012-7-6
 */
public class PutAssessmentId extends BaseTest {
  private static final SelLogger logger = SelLogger
      .getLogger(Assessment1.class);

  @Test
  public void s1_leadToAssessment() throws InterruptedException {
    getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Thread.sleep(3000);
    NavFinder.gotoTabPage(getWebDriver(), "Academics");
    LinkFinder
        .getLinkByText(getWebDriver(), AssessmentIdMapping.Test_CLassNAME)
        .click();
    NavFinder.gotoMenuOptionPage(getWebDriver(), "Assessments Editor");

    logger.pass("leadToAssessment  ");
  }

  @Test
  public void s2_putAssessmentId() throws InterruptedException {
    getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Thread.sleep(3000);
    List<WebElement> weList = ButtonFinder.getLinks(getWebDriver(),
        "Assessment", "href", "javascript:editAssessment");

    logger.pass("putAssessmentId : " + weList.size());
    Assert.assertTrue(weList.size() > 0, "putAssessmentId 0 ");
    for (int i = 0; i < weList.size(); i++) {
      String assessmentName = "Assessment" + (i + 1);
      String href = LinkFinder.getLinkByText(getWebDriver(), assessmentName,
          "javascript:editAssessment").getAttribute("href");
      String assessmentId = href.split("\\(")[1].split("\\,")[0];
    
      AssessmentIdMapping.putIdMapping(assessmentName, assessmentId);
    }
  }
}
